<template>
  <router-layout>
    <div class="container">
      <div class="van-hairline--top">
        <van-tabs v-model="active" color="#01A0EF">
          <van-tab title="公告消息">
            <div class="notice">
              <van-list v-model="loading" :finished="finished" @load="onLoad" :offset="0">
                <van-cell v-for="item in dataList" :key="item.id">
                  <div class="notice-list">
                    <div class="notice-title">
                      <p>{{item.notice_title}}</p>
                      <span>{{item.create_time}}</span>
                    </div>
                    <div class="notice-conent" v-html="item.notice_content"></div>
                    <!-- <Backtop></Backtop> -->
                  </div>
                </van-cell>
              </van-list>
            </div>
          </van-tab>
          <van-tab title="系统消息">
            <div class="notice">
              <van-list v-model="loading" :finished="finished" @load="onLoad" :offset="200">
                <van-cell v-for="item in messageList" :key="item.id">
                  <div class="notice-list">
                    <div class="notice-title">
                      <p>{{item.message_title}}</p>
                      <span>{{item.create_time}}</span>
                    </div>
                    <div class="notice-conent">{{item.message_content}}</div>
                    <!-- <Backtop></Backtop> -->
                  </div>
                </van-cell>
              </van-list>
            </div>
          </van-tab>
          <van-tab title="积分提醒">
            <div class="content-box">
              <Nodata v-if="!List.length"></Nodata>
              <van-list v-else v-model="loading" :finished="finished" @load="onLoad" :offset="200">
                <van-cell v-for="item in List" :key="item.id">
                  <div class="prize">
                    <div class="prize_list">
                      <div class="integral">
                        <p class="action">+{{item.score}}</p>
                        <p class="type">{{item.behavior_desc}}</p>
                      </div>
                      <div class="line"></div>
                      <div class="left">
                        <p class="name">{{item.create_time}}</p>
                        <p class="type">流水号：{{item.record_code}}</p>
                      </div>
                    </div>
                  </div>
                </van-cell>
              </van-list>
            </div>
          </van-tab>
        </van-tabs>
      </div>
    </div>
  </router-layout>
</template>

<script>
import Nodata from "../public/nodata/Nodata"; // 导入暂无数据组件
import TitleItem from "../../components/public/title/title";
import { notice_list, notice_listMessage } from "@/api/message";
import { admin_listIntegralRecord, admin_listIntegralType } from "@/api/admin";

export default {
  name: "CommunityHome",
  components: { TitleItem, Nodata },
  data() {
    return {
      loading: false,
      finished: false,
      active: 0,
      messageList: [],
      dataList: [],
      listQuery: {
        current: 1,
        limit: 5,
        company_id: localStorage.getItem("companyId") - 0
      },

      List: []
    };
  },
  methods: {
    //切换tab栏
    onClick(index, title) {
      if (index == 0) {
        this.listQuery.order_by = "";
      }
      if (index == 1) {
        this.listQuery.order_by = "read";
      }
      if (index == 2) {
        this.listQuery.order_by = "like";
      }
      this.initList();
      this.messageList1();
      this.integralList();
    },

    async integralList() {
      //获取积分提醒
      let query = Object.assign({}, this.listQuery);
      let { data } = await admin_listIntegralRecord(query);
      if (data.status == 100) {
        this.List = data.data.rows;
        this.total = data.data.results;
      }
      this.loading = false;
      if (data.data.results <= this.List.length) {
        this.finished = true;
      }
    },

    //获取系统消息数据
    async messageList1() {
      //公告消息接口
      let query = Object.assign({}, this.listQuery);
      let res = await notice_listMessage(query);
      let result = res.data;
      if (result.status == 100) {
        this.messageList = result.data.rows;
      }
      this.loading = false;

      if (result.data.results <= this.messageList.length) {
        this.finished = true;
      }
    },
    //获取公告数据
    async initList() {
      //公告消息接口
      let query = Object.assign({}, this.listQuery);
      let res = await notice_list(query);
      let result = res.data;
      if (result.status == 100) {
        this.dataList = result.data.rows;
      }
      this.loading = false;
      if (result.data.results <= this.dataList.length) {
        this.finished = true;
      }
    },
    onLoad() {
      setTimeout(() => {
        this.listQuery.limit += 5;
        this.initList();
        this.messageList1();
        this.integralList();
      }, 1000);
    }
  },
  created() {
    this.initList();
    this.integralList();
    this.messageList1();
  }
};
</script>

<style lang="scss" scoped>
@import "messageHome";
</style>
